package com.ruoyi.web.controller.system;

import com.ruoyi.collector.service.SyslogListener;
import com.ruoyi.elastic.config.ElasticClient;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysLogStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 *
 * @author ruoyi
 */
@Api(value = "syslog管理Controller",tags = "syslog管理Controller")

@RestController
@RequestMapping("/system/syslog")
public class SyslogController extends BaseController
{
    private ElasticClient elasticClient;
    @Autowired
    private SyslogListener syslogListener;

    /**
     * 获取状态
     */
//    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @ApiOperation("获取syslog服务状态")
    @GetMapping("/getStatus")
    public boolean getStatus() {
        return syslogListener.checkSyslogServer();
    }

    /**
     * 状态修改
     */
//    @PreAuthorize("@ss.hasPermi('system:user:edit')")
//    @Log(title = "更新syslog状态", businessType = BusinessType.)
    @ApiOperation("更新syslog状态")
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysLogStatus sysLogStatus) {
        if(sysLogStatus.isStatus()){
            return toAjax(syslogListener.startSyslogServer());
        }else {
            return toAjax(syslogListener.stopSyslogServer());
        }
    }

}
